import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiQuery, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { DoctorService } from './doctor.service';
import { CreateDoctorDto } from './dto/create-doctor.dto';
import { UpdateDoctorDto } from './dto/update-doctor.dto';
import { Doctor } from './entities/doctor.entity';
import { Response } from '../../infra/schema/response';
import { Public } from '../auth/auth.decorator';

@ApiTags('医生')
@Controller('doctor')
export class DoctorController {
  constructor(private readonly doctorService: DoctorService) {}

  @Public()
  @Post()
  @ApiOperation({ summary: '创建医生信息' })
  @ApiResponse({ status: 201, description: '医生信息创建成功', type: Doctor })
  create(@Body() createDoctorDto: CreateDoctorDto) {
    return this.doctorService.create(createDoctorDto);
  }

  // @Public()
  // @Get()
  // @ApiOperation({ summary: '获取所有医生信息' })
  // @ApiResponse({
  //   status: 200,
  //   description: '成功获取所有医生信息',
  //   type: [Doctor],
  // })
  // findAll() {
  //   return this.doctorService.findAll();
  // }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: '根据 ID 获取单个医生信息' })
  @ApiResponse({ status: 200, description: '成功获取医生信息', type: Doctor })
  @ApiResponse({ status: 404, description: '医生信息不存在' })
  findOne(@Param('id') id: string) {
    return this.doctorService.findOne(+id);
  }

  @Put(':id')
  @ApiOperation({ summary: '根据 ID 更新医生信息' })
  @ApiResponse({ status: 200, description: '医生信息更新成功', type: Doctor })
  @ApiResponse({ status: 404, description: '医生信息不存在' })
  update(@Param('id') id: string, @Body() updateDoctorDto: UpdateDoctorDto) {
    return this.doctorService.update(+id, updateDoctorDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '根据 ID 删除医生信息' })
  @ApiResponse({ status: 200, description: '医生信息删除成功', type: Doctor })
  @ApiResponse({ status: 404, description: '医生信息不存在' })
  remove(@Param('id') id: string) {
    return this.doctorService.remove(+id);
  }

  @Public()
  @ApiQuery({
    name: 'page',
    type: Number,
    required: false,
    description: '当前页码，默认 1',
  })
  @ApiQuery({
    name: 'size',
    type: Number,
    required: false,
    description: '每页数量，默认 10',
  })
  @ApiQuery({
    name: 'status',
    enum: ['pending', 'approved', 'rejected'],
    required: false,
    description: '医生审核状态',
  })
  @Get()
  async getDoctorList(
    @Query('page') page: number = 1,
    @Query('size') size: number = 10,
    @Query('status') status?: 'pending' | 'approved' | 'rejected',
  ) {
    console.log(page, size, status, 'sssssssssssssssssssssssssssssssssss');

    const result = await this.doctorService.getDoctorList({
      page,
      size,
      status,
    });
    return Response.successList(result.data, result.total);
  }
}
